﻿package mortal.game.scene3D.ai.ais
{
    import flash.events.*;
    import flash.utils.*;
    import frEngine.event.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.scene3D.ai.base.*;
    import mortal.game.scene3D.events.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.mvc.core.*;

    public class FightOnceAI extends AICommand
    {
        private var _timerId:int;

        public function FightOnceAI()
        {
            return;
        }// end function

        override public function start(param1:Function = null) : void
        {
            super.start(param1);
            Dispatcher.dispatchEvent(new DataEvent(EventName.SkillAskServerUseSkill, _data));
            FrEventDispatcher.instance.proxyAddEventListener(RolePlayer.instance, PlayerEvent.SkillPointEnd, this.skillEndHandler);
            Dispatcher.addEventListener(EventName.SkillFlashInto, this.flashIntoHandler);
            this._timerId = setTimeout(this.skillEndHandler, 4000);
            return;
        }// end function

        private function flashIntoHandler(event:DataEvent) : void
        {
            this.stop();
            return;
        }// end function

        private function skillEndHandler(event:Event = null) : void
        {
            this.stop();
            return;
        }// end function

        override public function stop(param1:Boolean = true) : void
        {
            if (this._timerId > 0)
            {
                clearTimeout(this._timerId);
                this._timerId = -1;
            }
            FrEventDispatcher.instance.proxyRemoveEventListener(RolePlayer.instance, PlayerEvent.SkillPointEnd, this.skillEndHandler);
            Dispatcher.removeEventListener(EventName.SkillFlashInto, this.flashIntoHandler);
            super.stop(param1);
            return;
        }// end function

    }
}
